﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace HQWeb.View.Order
{
    public partial class DownLoad : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
            if (!IsPostBack)
            {
                string strFile = Request.QueryString["filePath"];//HttpUtility.UrlEncode(Request["filePath"], System.Text.Encoding.UTF8);
                string strFileName = Request.QueryString["name"].ToString();

                FileInfo DownloadFile = new FileInfo(strFile); //设置要下载的文件
                Response.Clear();                            //清除缓冲区流中的所有内容输出
                Response.ClearHeaders();                     //清除缓冲区流中的所有头
                Response.Buffer = false;                     //设置缓冲输出为false
                //设置输出流的 HTTP MIME 类型为application/octet-stream
                Response.ContentType = "application/octet-stream";
                //将 HTTP 头添加到输出流
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Trim(), System.Text.Encoding.UTF8));
                Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
                //将指定的文件直接写入 HTTP 内容输出流。
                Response.WriteFile(DownloadFile.FullName);
                Response.Flush();       //向客户端发送当前所有缓冲的输出
                Response.End();         //将当前所有缓冲的输出发送到客户端
            }
        }
    }
}